package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetMealService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/mobile")
@ResponseBody
public class MobileController {

    @Reference
    private SetMealService setMealService;

    @RequestMapping("/findSetMeal")
    public Result findSetMeal(){
        boolean flag=false;
        String message=null;
        List<Setmeal>setmealList= null;
        try {
            setmealList = setMealService.findSetMeal();
            flag=true;
            message= MessageConstant.QUERY_SETMEALLIST_SUCCESS;
        } catch (Exception e) {
            message= MessageConstant.QUERY_SETMEALLIST_FAIL;
            e.printStackTrace();
        }
        return new Result(flag,message,setmealList);
    }

    @RequestMapping("/findAllSetMeal")
    public Result findAllSetMeal(Integer id){
        boolean flag=false;
        String message=null;
        Setmeal setMeal= null;
        try {
            setMeal = setMealService.findAllSetMeal(id);
            flag=true;
            message=MessageConstant.QUERY_SETMEAL_SUCCESS;
        } catch (Exception e) {
            message=MessageConstant.QUERY_SETMEAL_FAIL;
            e.printStackTrace();
        }
        return new Result(flag,message,setMeal);
    }

    @RequestMapping("/findSetMealById")
    public Result findSetMealById(Integer id){
        boolean flag=false;
        String message=null;
        Setmeal setMeal= null;
        try {
            setMeal = setMealService.findSetMealById(id);
            flag=true;
            message=MessageConstant.QUERY_SETMEAL_SUCCESS;
        } catch (Exception e) {
            message=MessageConstant.QUERY_SETMEAL_FAIL;
            e.printStackTrace();
        }
        return new Result(flag,message,setMeal);
    }
}
